Fix a repeated `cargo test` with examples
authorAlex Crichton <alex@alexcrichton.com>
Wed, 29 Oct 2014 23:33:52 +0000 (16:33 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Wed, 29 Oct 2014 23:49:59 +0000 (16:49 -0700)
The examples output directory was accidentally taken into account twice, and
this removes one source of the output directory confusion.

src/cargo/ops/cargo_rustc/context.rs
tests/test_cargo_test.rs

index e3e22b3431aec98a7ced07d5158fa5c210edb6a8..47751b8ee5367f74fa45fe2202c84fef4ba5b65d 100644 (file)
@@ -225,9 +225,8 @@ impl<'a, 'b> Context<'a, 'b> {
         let stem = target.file_stem();
 
         let mut ret = Vec::new();
-        if target.is_example() {
-            ret.push(format!("examples/{}{}", stem, self.target_exe));
-        } else if target.is_bin() || target.get_profile().is_test() {
+        if target.is_example() || target.is_bin() ||
+           target.get_profile().is_test() {
             ret.push(format!("{}{}", stem, self.target_exe));
         } else {
             if target.is_dylib() {
index 901499c44d0d67fadcdf30341a047077226f3655..89d7f9e277db9b0c820ea339b5a456594f40072a 100644 (file)
@@ -1254,3 +1254,24 @@ test!(example_bin_same_name {
     assert_that(p.process(p.bin("examples/foo")),
                 execs().with_status(0).with_stdout("example\n"));
 })
+
+test!(test_with_example_twice {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+        "#)
+        .file("src/bin/foo.rs", r#"fn main() { println!("bin"); }"#)
+        .file("examples/foo.rs", r#"fn main() { println!("example"); }"#);
+
+    println!("first");
+    assert_that(p.cargo_process("test").arg("-v"),
+                execs().with_status(0));
+    assert_that(&p.bin("examples/foo"), existing_file());
+    println!("second");
+    assert_that(p.process(cargo_dir().join("cargo")).arg("test").arg("-v"),
+                execs().with_status(0));
+    assert_that(&p.bin("examples/foo"), existing_file());
+})